package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/follow")
@CrossOrigin//允许跨域请求
@Slf4j
public class FollowController {

    @Resource
    private IFollowService followService;
    /**
     * 关注/取消关注某个用户<br>
     * /follow/{followUserId}/true<br>
     * PUT<br>
     * 请求参数：<br>
     * followUserId：关注的用户ID<br>
     * 是否关注：true/false<br>
     */
    @PutMapping("/{id}/{isFollow}")
    public Result isFollow(@PathVariable("id") Long followUserId, @PathVariable("isFollow") Boolean isFollow) {
        return followService.follow(followUserId, isFollow);
    }


    /**
     * 查询是否关注某个用户<br>
     * /follow/or/not/{followUserId}<br>
     * GET<br>
     * 请求参数：<br>
     * followUserId：关注的用户ID<br>
     * 返回结果：<br>
     * 是否关注：true/false<br>
     */
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId) {
        return followService.isFollow(followUserId);
    }


    /**
     * 和当前用户的共同关注用户列表查询
     */
    @GetMapping("/common/{id}")
    public Result followCommons(@PathVariable("id") Long id) {
        return followService.followCommons(id);
    }


}
